package com.zijie.shopgoodsapi.goods.service;

import com.zijie.brand.model.Brand;
import com.zijie.category.model.Category;
import com.zijie.core.util.JsonResult;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@FeignClient(name = "shop-gateway", contextId = "brand-api", fallback = BrandFeignServiceFallback.class)
public interface BrandFeignService {
    @GetMapping("/brand-api/api/v1/brand/findById/{id}")
    public ResponseEntity<JsonResult<Brand>> findById(@PathVariable("id") Integer id);


}
@Component
class BrandFeignServiceFallback implements BrandFeignService {
    //接受同样的参数，处理降级的响应
    @Override
    public ResponseEntity<JsonResult<Brand>> findById(Integer id) {
        return ResponseEntity.status(503)
                .body(new JsonResult<>("503", "不好意思，下游服务异常", null));
    }
}
